package com.example.leetcode.trainingcamp.week2.practice;

public class Test83 {

    // 1 1 1 2 3 4 4     -> 1 2 3 4

    public ListNode deleteDuplicates(ListNode head) {
        ListNode pre = new ListNode();
        ListNode now = pre;
        while(head != null){
            if(head.next == null || head.val != head.next.val){
                now.next = head;
                now = head;
            }
            head = head.next;
        }
        now.next = null;
        return pre.next;
    }

    public ListNode deleteDuplicates2(ListNode head) {
        if (head == null) {
            return head;
        }

        ListNode cur = head;
        while (cur.next != null) {
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }

        return head;

    }

}


class Demo83{
  public static void main(String[] args) {
    ListNode node1 = new ListNode(1);
    node1.next = new ListNode(1);
    node1.next.next = new ListNode(2);
    Test83 t = new Test83();
    ListNode node = t.deleteDuplicates(node1);
    while (node!= null){
      System.out.print(node.val+",");
      node = node.next;
    }
  }
}